package com.mooco.dongba.sys.service.impl;

import com.mooco.dongba.common.exception.ServiceException;
import com.mooco.dongba.common.pojo.PageObject;
import com.mooco.dongba.sys.dao.SysUserDao;
import com.mooco.dongba.sys.dao.SysUserRoleDao;
import com.mooco.dongba.sys.pojo.SysUser;
import com.mooco.dongba.sys.pojo.SysUserDeptVo;
import com.mooco.dongba.sys.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class SysUserServiceImplEx {
    @Autowired
    private SysUserDao sysUserDao;

    @Autowired
    private SysUserRoleDao sysUserRoleDao;

    public PageObject<SysUserDeptVo> findPageObject(String username, Integer pageCurrent) {
        // 1、参数校验
        if (pageCurrent == null || pageCurrent <= 0) {
            throw new IllegalArgumentException("当前页码值无效");
        }

        // 2、获取总记录数
        int rowCount = sysUserDao.getRowCount(username);
        if (rowCount == 0)
            throw new ServiceException("没有找到对应的记录");
        int pageSize = 2;
        int startIndex = (pageCurrent - 1) * pageSize;

        // 3、获取分页数据，并返回
        List<SysUserDeptVo> records = sysUserDao.findPageObjects(username, startIndex, pageSize);
        return new PageObject<SysUserDeptVo>(rowCount, pageSize, pageCurrent, records);
    }
}
